/*

Replication code for Vytautas Kuokštis and Simonas Algirdas Spurga, 
"The Political Economy of Exchange Rate Regimes and External (Im)Balances: The Role of Labor Market Institutions", 
Working Paper. 

Note: requires estout package; type "net search estout" if needed

*/


use Labor_Balance.dta, clear

xtset CountryID Year

*** generate current account and trade balance without outliers
gen CAB = CAbalanceGDP if CAbalanceGDP  > -50 & CAbalanceGDP < 50
gen trade = Externalbalanceongoodsandse if Externalbalanceongoodsandse> -50 & Externalbalanceongoodsandse < 50

*** generate positive EPL variable and recode ER regime variable to increase in rigidity

sum EPL
gen EPL_p = 5 + .0933333 - EPL if EPL!=.

gen lCoarse_rev = l.Coarse_rev

*** Figures 1 and 2

* above EPL average

mean trade if EPL_p !=. & EPL_p > 2.9 & l.Coarse_rev==1
mean trade if EPL_p !=. & EPL_p > 2.9 & l.Coarse_rev==2
mean trade if EPL_p !=. & EPL_p > 2.9 & l.Coarse_rev==3
mean trade if EPL_p !=. & EPL_p > 2.9 & l.Coarse_rev==4

* below EPL average

mean trade if EPL_p !=. & EPL_p < 2.9 & l.Coarse_rev==1
mean trade if EPL_p !=. & EPL_p < 2.9 & l.Coarse_rev==2
mean trade if EPL_p !=. & EPL_p < 2.9 & l.Coarse_rev==3
mean trade if EPL_p !=. & EPL_p < 2.9 & l.Coarse_rev==4

* above EPL average

mean CAB if EPL_p !=. & EPL_p > 2.9 & l.Coarse_rev==1
mean CAB if EPL_p !=. & EPL_p > 2.9 & l.Coarse_rev==2
mean CAB if EPL_p !=. & EPL_p > 2.9 & l.Coarse_rev==3
mean CAB if EPL_p !=. & EPL_p > 2.9 & l.Coarse_rev==4


* below EPL average

mean CAB if EPL_p !=. & EPL_p < 2.9 & l.Coarse_rev==1
mean CAB if EPL_p !=. & EPL_p < 2.9 & l.Coarse_rev==2
mean CAB if EPL_p !=. & EPL_p < 2.9 & l.Coarse_rev==3
mean CAB if EPL_p !=. & EPL_p < 2.9 & l.Coarse_rev==4


clear
input Coarse_rev EPL_p_above Mean_trade Std_err
1 1 -0.8556305 0.1695121
2 1  1.714513  0.3283228
3 1  2.230245  0.6193664
4 1  7.621849  0.8163867
1 0 -0.769249  0.3412348
2 0  2.40415   0.3845574
3 0 -0.7041232 0.4515363
4 0  0.4469927 0.3319113
end

twoway (line Mean_trade Coarse_rev if EPL_p_above == 1, lcolor(blue) lpattern(solid)) (line Mean_trade Coarse_rev if EPL_p_above == 0, lcolor(red) lpattern(dash)), ytitle("Mean trade balance (percentage of GDP)") xtitle("ERR - increasing fixity") legend(order(1 "Flexible LM" 2 "Rigid LM") position(10) ring(0))

graph export "Figure1.png", replace

clear
input Coarse_rev EPL_p_above Mean_CAB Std_err
1 1 -1.937853 0.254813
2 1 -0.2032752 0.5019274
3 1 -1.66477 0.4050321
4 1  2.521286 0.4703463
1 0 -0.7201061 0.6717382
2 0  1.007043 0.3937128
3 0 -0.9864769 0.3428063
4 0 -0.098674 0.3138652
end

twoway (line Mean_CAB Coarse_rev if EPL_p_above == 1, lcolor(blue) lpattern(solid)) (line Mean_CAB Coarse_rev if EPL_p_above == 0, lcolor(red) lpattern(dash)), ytitle("Mean CA balance (percentage of GDP)") xtitle("ERR - increasing fixity") legend(order(1 "Flexible LM" 2 "Rigid LM") position(10) ring(0))

graph export "Figure2.png", replace


use Labor_Balance.dta, clear

gen CAB = CAbalanceGDP if CAbalanceGDP  > -50 & CAbalanceGDP < 50
gen trade = Externalbalanceongoodsandse if Externalbalanceongoodsandse> -50 & Externalbalanceongoodsandse < 50
gen ln_gdp_pc = log( GDPpercapitaconstant2015US)
gen ln_pop = log( Populationtotal)
gen IIP_gdp = NetIIPexclgold / GDPUSD
gen ltrade = l.trade
gen lCAB = l.CAB
gen EPL_p = 5 + .0933333 - EPL if EPL!=.
gen lCoarse_rev = l.Coarse_rev


gen Fixed_hard = Coarse_rev
replace Fixed_hard = 1 if  Coarse_rev == 4
replace Fixed_hard = 0 if Coarse_rev == 3 |Coarse_rev == 2 | Coarse_rev == 1



*** Correlations between ERR and trade / current account balance for different levels of labor market flexibility:
cor trade Coarse_rev if EPL_p > 2.9 & EPL_p !=.
cor trade Coarse_rev if EPL_p < 2.9 & EPL_p !=.
cor CAB Coarse_rev if EPL_p > 2.9 & EPL_p !=.
cor CAB Coarse_rev if EPL_p < 2.9 & EPL_p !=.

*** Appendix, Table A1 Descriptive Statistics

foreach var in CAB trade Coarse_rev Fixed_hard EPL_p labor ln_pop ln_gdp_pc IMF_fiscal kaopen GDPgr Fuel Age IIP_gdp ETCR cce rqe {
    bysort Country: egen max_`var' = max(!missing(`var'))
}
collapse (max) max_*, by(Country)

save temp_country_data.dta, replace

use Labor_Balance.dta, clear

foreach var in CAB trade Coarse_rev Fixed_hard EPL_p labor ln_pop ln_gdp_pc IMF_fiscal kaopen GDPgr Fuel Age IIP_gdp ETCR cce rqe {
    su `var', detail
    local obs_`var' = r(N)
    local mean_`var' = r(mean)
    local sd_`var' = r(sd)
    local min_`var' = r(min)
    local max_`var' = r(max)
}

use temp_country_data.dta, clear
local vars CAB trade Coarse_rev Fixed_hard EPL_p labor ln_pop ln_gdp_pc IMF_fiscal kaopen GDPgr Fuel Age IIP_gdp ETCR cce rqe
foreach var in `vars' {
    count if max_`var' == 1
    local nCountries_`var' = r(N)
}

clear
set obs 17
gen variable = ""
gen n_countries = .
gen obs = .
gen mean = .
gen sd = .
gen min = .
gen max = .

local i = 1
foreach var in `vars' {
    replace variable = "`var'" in `i'
    replace n_countries = `nCountries_`var'' in `i'
    replace obs = `obs_`var'' in `i'
    replace mean = `mean_`var'' in `i'
    replace sd = `sd_`var'' in `i'
    replace min = `min_`var'' in `i'
    replace max = `max_`var'' in `i'
    local i = `i' + 1
}

asdoc list variable n_countries obs mean sd min max, clean noobs replace save(Descriptives_table.doc)



*** Appendix, Table A2

use Labor_Balance.dta, clear

gen CAB = CAbalanceGDP if CAbalanceGDP  > -50 & CAbalanceGDP < 50
gen trade = Externalbalanceongoodsandse if Externalbalanceongoodsandse> -50 & Externalbalanceongoodsandse < 50
gen ln_gdp_pc = log( GDPpercapitaconstant2015US)
gen ln_pop = log( Populationtotal)
gen IIP_gdp = NetIIPexclgold / GDPUSD
gen ltrade = l.trade
gen lCAB = l.CAB
gen EPL_p = 5 + .0933333 - EPL if EPL!=.
gen lCoarse_rev = l.Coarse_rev


gen Fixed_hard = Coarse_rev
replace Fixed_hard = 1 if  Coarse_rev == 4
replace Fixed_hard = 0 if Coarse_rev == 3 |Coarse_rev == 2 | Coarse_rev == 1


xtset CountryID Year

mixed trade i.Year c.l.Coarse_rev if l.EPL_p!=. || CountryID: l.Coarse_rev
eststo model1
 
mixed trade i.Year l.ln_pop l.ln_gdp_pc l.IMF_fiscal l.kaopen l.GDPgr l.Fuel l.Age l.IIP_gdp c.l.Coarse_rev if l.EPL_p!=. || CountryID: l.Coarse_rev
eststo model2

mixed CAB i.Year c.l.Coarse_rev if l.EPL_p!=. || CountryID: l.Coarse_rev
eststo model3

mixed CAB i.Year l.ln_pop l.ln_gdp_pc l.IMF_fiscal l.kaopen l.GDPgr l.Fuel l.Age l.IIP_gdp c.l.Coarse_rev if l.EPL_p!=. || CountryID: l.Coarse_rev
eststo model4

esttab model1 model2 model3 model4 using "TableA2.doc", drop(*.Year lns1_1_1:_cons lns1_1_2:_cons lnsig_e:_cons) replace se rtf varlabels(L.Coarse_rev "ERR_{t-1}" L.ln_pop "LogPopulation_{t-1}" L.ln_gdp_pc "LogGDPpc_{t-1}" L.IMF_fiscal_balance "FiscalBalance_{t-1}" L.kaopen "Openness_{t-1}" L.GDPgrowthannual "GDPgrowth_{t-1}" L.Fuelexports "FuelExports_{t-1}" L.Agedependencyratioold "AgeDependencyRatio_{t-1}" L.IIP_gdp "IIPtoGDP_{t-1}") stats(p N, fmt(%9.3f %9.0f) labels("p" "N")) mtitles ("Model 1 (trade)" "Model 2 (trade)" "Model 3 (CAB)" "Model 4 (CAB)") nonumbers nodepvars star(* 0.1 ** 0.05 *** 0.01)



*** Table 1

mixed trade i.Year c.l.Coarse_rev##c.l.EPL_p  if l.EPL_p!=. || CountryID: l.Coarse_rev
eststo model1

mixed trade i.Year l.ln_pop l.ln_gdp_pc l.IMF_fiscal l.kaopen l.GDPgr l.Fuel l.Age l.IIP_gdp c.l.Coarse_rev##c.l.EPL_p if l.EPL_p!=. || CountryID: l.Coarse_rev
eststo model2

mixed CAB i.Year c.l.Coarse_rev##c.l.EPL_p if l.EPL_p!=. || CountryID: l.Coarse_rev
eststo model3

mixed CAB i.Year l.ln_pop l.ln_gdp_pc l.IMF_fiscal l.kaopen l.GDPgr l.Fuel l.Age l.IIP_gdp c.l.Coarse_rev##c.l.EPL_p if l.EPL_p!=. || CountryID: l.Coarse_rev
eststo model4

esttab model1 model2 model3 model4 using "Table1.doc", drop(*.Year lns1_1_1:_cons lns1_1_2:_cons lnsig_e:_cons) replace se rtf varlabels(L.Coarse_rev "ERR_{t-1}" L.EPL_p "EPL_{t-1}" cL.Coarse_rev#cL.EPL_p "ERR_{t-1}#EPL_{t-1}" L.ln_pop "LogPopulation_{t-1}" L.ln_gdp_pc "LogGDPpc_{t-1}" L.IMF_fiscal_balance "FiscalBalance_{t-1}" L.kaopen "Openness_{t-1}" L.GDPgrowthannual "GDPgrowth_{t-1}" L.Fuelexports "FuelExports_{t-1}" L.Agedependencyratioold "AgeDependencyRatio_{t-1}" L.IIP_gdp "IIPtoGDP_{t-1}") stats(p N, fmt(%9.3f %9.0f) labels("P" "N")) mtitles ("Model 1 (trade)" "Model 2 (trade)" "Model 3 (CAB)" "Model 4 (CAB)") nonumbers nodepvars star(* 0.1 ** 0.05 *** 0.01)



*** Figures 3 and 4 (marginal effects plots)

mixed trade i.Year l.ln_pop l.ln_gdp_pc l.IMF_fiscal l.kaopen l.GDPgr l.Fuel l.Age l.IIP_gdp c.l.Coarse_rev##c.l.EPL_p if l.EPL_p!=. || CountryID: l.Coarse_rev
margins, dydx(l.Coarse_rev) at(l.EPL_p = (0.1 (0.1) 5))
marginsplot, yline(0) xtitle("EPL (Lagged)") title("")
graph export "Figure3.png", replace

mixed CAB i.Year l.ln_pop l.ln_gdp_pc l.IMF_fiscal l.kaopen l.GDPgr l.Fuel l.Age l.IIP_gdp c.l.Coarse_rev##c.l.EPL_p if l.EPL_p!=. || CountryID: l.Coarse_rev
margins, dydx(l.Coarse_rev) at(l.EPL_p = (0.1 (0.1) 5))
marginsplot, yline(0) xtitle("EPL (Lagged)") title("")
graph export "Figure4.png", replace

*** Tables 2 and 3 - Hierarchical model results excluding one country at a time

quietly levelsof CountryID if l.EPL_p != ., local(countries)

local num_countries = wordcount("`countries'")

matrix coeffs = J(`num_countries', 1, .)
matrix pvalues = J(`num_countries', 1, .)

local i = 1
foreach country of local countries {
    display "Excluding country: `country'"
    
    quietly mixed trade i.Year l.ln_pop l.ln_gdp_pc l.IMF_fiscal l.kaopen l.GDPgr l.Fuel l.Age l.IIP_gdp c.l.Coarse_rev##c.l.EPL_p if l.EPL_p != . & CountryID != `country' || CountryID: l.Coarse_rev l.EPL_p
    
    local coef = _b[c.l.Coarse_rev#c.l.EPL_p]
    local se = _se[c.l.Coarse_rev#c.l.EPL_p]
    
    local z = `coef' / `se'
    local pvalue = 2 * normal(-abs(`z'))
    
    matrix coeffs[`i', 1] = `coef'
    matrix pvalues[`i', 1] = `pvalue'
    
    local i = `i' + 1
}

* Display the results
matrix list coeffs
matrix list pvalues
svmat coeffs, name(Coef_Interaction)
svmat pvalues, name(PValue_Interaction)
quietly summarize Coef_Interaction PValue_Interaction
quietly summarize PValue_Interaction
local mean_pvalue = string(r(mean), "%9.2e")
asdoc summarize Coef_Interaction PValue_Interaction, replace save(Table2.doc) // interaction term in all models highly significant



*** Table A3 - Dynamic models (lagged DV included)

reg trade ltrade i.Year c.l.Coarse_rev##c.l.EPL_p l.ln_pop l.ln_gdp_pc l.IMF_fiscal l.kaopen l.GDPgr l.Fuel l.Age l.IIP_gdp if l.EPL_p!=., cluster(CountryID)

eststo model1


reg CAB lCAB i.Year c.l.Coarse_rev##c.l.EPL_p l.ln_pop l.ln_gdp_pc l.IMF_fiscal l.kaopen l.GDPgr l.Fuel l.Age l.IIP_gdp if l.EPL_p!=., cluster(CountryID)

eststo model2

esttab model1 model2 using "TableA3.doc", drop(*.Year) replace se rtf varlabels(ltrade "TradeBalance_{t-1}" lCAB "CAB_{t-1}" L.Coarse_rev "ERR_{t-1}" L.EPL_p "EPL_{t-1}" cL.Coarse_rev#cL.EPL_p "ERR_{t-1}#EPL_{t-1}" L.ln_pop "LogPopulation_{t-1}" L.ln_gdp_pc "LogGDPpc_{t-1}" L.IMF_fiscal_balance "FiscalBalance_{t-1}" L.kaopen "Openness_{t-1}" L.GDPgrowthannual "GDPgrowth_{t-1}" L.Fuelexports "FuelExports_{t-1}" L.Agedependencyratioold "AgeDependencyRatio_{t-1}" L.IIP_gdp "IIPtoGDP_{t-1}") stats(p N, fmt(%9.3f %9.0f) labels("P" "N")) mtitles ("Model 1 (trade)" "Model 2 (CAB)") nonumbers nodepvars star(* 0.1 ** 0.05 *** 0.01)



*** Table A4 - developed vs developing

mixed trade i.Year c.l.Coarse_rev##c.l.EPL_p l.ln_pop l.ln_gdp_pc l.IMF_fiscal l.kaopen l.GDPgr l.Fuel l.Age l.IIP_gdp if l.EPL_p!=. & developed == 1|| CountryID: l.Coarse_rev 

eststo model1

mixed trade i.Year c.l.Coarse_rev##c.l.EPL_p l.ln_pop l.ln_gdp_pc l.IMF_fiscal l.kaopen l.GDPgr l.Fuel l.Age l.IIP_gdp if l.EPL_p!=. & developed == 0|| CountryID: l.Coarse_rev 

eststo model2

mixed CAB i.Year c.l.Coarse_rev##c.l.EPL_p l.ln_pop l.ln_gdp_pc l.IMF_fiscal l.kaopen l.GDPgr l.Fuel l.Age l.IIP_gdp if l.EPL_p!=. & developed == 1|| CountryID: l.Coarse_rev 

eststo model3

mixed CAB i.Year c.l.Coarse_rev##c.l.EPL_p l.ln_pop l.ln_gdp_pc l.IMF_fiscal l.kaopen l.GDPgr l.Fuel l.Age l.IIP_gdp if l.EPL_p!=. & developed == 0|| CountryID: l.Coarse_rev 

eststo model4

esttab model1 model2 model3 model4 using "TableA4.doc", drop(*.Year lns1_1_1:_cons lns1_1_2:_cons lnsig_e:_cons) replace se rtf varlabels(L.Coarse_rev "ERR_{t-1}" L.EPL_p "EPL_{t-1}" cL.Coarse_rev#cL.EPL_p "ERR_{t-1}#EPL_{t-1}" L.ln_pop "LogPopulation_{t-1}" L.ln_gdp_pc "LogGDPpc_{t-1}" L.IMF_fiscal_balance "FiscalBalance_{t-1}" L.kaopen "Openness_{t-1}" L.GDPgrowthannual "GDPgrowth_{t-1}" L.Fuelexports "FuelExports_{t-1}" L.Agedependencyratioold "AgeDependencyRatio_{t-1}" L.IIP_gdp "IIPtoGDP_{t-1}") stats(p N, fmt(%9.3f %9.0f) labels("P" "N")) mtitles ("Model 1 (trade)" "Model 2 (trade)" "Model 3 (CAB)" "Model 4 (CAB)") nonumbers nodepvars star(* 0.1 ** 0.05 *** 0.01)


*** Table 4 - Product market regulation

mixed trade i.Year c.l.Coarse_rev##c.l.EPL_p c.l.ETCR l.ln_pop l.ln_gdp_pc l.IMF_fiscal l.kaopen l.GDPgr l.Fuel l.Age l.IIP_gdp if l.EPL_p!=. || CountryID: l.Coarse_rev 

eststo model1

mixed trade i.Year c.l.Coarse_rev##c.l.EPL_p c.l.Coarse_rev##c.l.ETCR l.ln_pop l.ln_gdp_pc l.IMF_fiscal l.kaopen l.GDPgr l.Fuel l.Age l.IIP_gdp if l.EPL_p!=. || CountryID: l.Coarse_rev 

eststo model2

mixed trade i.Year c.l.Coarse_rev##c.l.EPL_p##c.l.ETCR l.ln_pop l.ln_gdp_pc l.IMF_fiscal l.kaopen l.GDPgr l.Fuel l.Age l.IIP_gdp if l.EPL_p!=. || CountryID: l.Coarse_rev 

eststo model3


mixed CAB i.Year c.l.Coarse_rev##c.l.EPL_p c.l.ETCR l.ln_pop l.ln_gdp_pc l.IMF_fiscal l.kaopen l.GDPgr l.Fuel l.Age l.IIP_gdp if l.EPL_p!=. || CountryID: l.Coarse_rev 

eststo model4

mixed CAB i.Year c.l.Coarse_rev##c.l.EPL_p c.l.Coarse_rev##c.l.ETCR l.ln_pop l.ln_gdp_pc l.IMF_fiscal l.kaopen l.GDPgr l.Fuel l.Age l.IIP_gdp if l.EPL_p!=. || CountryID: l.Coarse_rev 

eststo model5

mixed CAB i.Year c.l.Coarse_rev##c.l.EPL_p##c.l.ETCR l.ln_pop l.ln_gdp_pc l.IMF_fiscal l.kaopen l.GDPgr l.Fuel l.Age l.IIP_gdp if l.EPL_p!=. || CountryID: l.Coarse_rev 

eststo model6

esttab model1 model2 model3 model4 model5 model6 using "Table4.doc", drop(*.Year lns1_1_1:_cons lns1_1_2:_cons lnsig_e:_cons) replace se rtf varlabels(L.Coarse_rev "ERR_{t-1}" L.EPL_p "EPL_{t-1}" cL.Coarse_rev#cL.EPL_p "ERR_{t-1}#EPL_{t-1}" L.ETCR "ETCR_{t-1}" cL.Coarse_rev#cL.ETCR "ERR_{t-1}#ETCR_{t-1}" cL.EPL_p#cL.ETCR "EPL_{t-1}#ETCR_{t-1}" cL.Coarse_rev#cL.EPL_p#cL.ETCR "ERR_{t-1}#EPL_{t-1}#ECTR_{t-1}" L.ln_pop "LogPopulation_{t-1}" L.ln_gdp_pc "LogGDPpc_{t-1}" L.IMF_fiscal_balance "FiscalBalance_{t-1}" L.kaopen "Openness_{t-1}" L.GDPgrowthannual "GDPgrowth_{t-1}" L.Fuelexports "FuelExports_{t-1}" L.Agedependencyratioold "AgeDependencyRatio_{t-1}" L.IIP_gdp "IIPtoGDP_{t-1}") stats(p N, fmt(%9.3f %9.0f) labels("P" "N")) mtitles ("Model 1 (trade)" "Model 2 (trade)" "Model 3 (trade)" "Model 4 (CAB)" "Model 5 (CAB)" "Model 6 (CAB)") nonumbers nodepvars star(* 0.1 ** 0.05 *** 0.01)



*** Table A5 - corruption control and regulatory quality

mixed trade i.Year c.l.Coarse_rev##c.l.EPL_p l.cce l.ln_pop l.ln_gdp_pc l.IMF_fiscal l.kaopen l.GDPgr l.Fuel l.Age l.IIP_gdp if l.EPL_p!=. || CountryID: l.Coarse_rev 

eststo model1

mixed CAB i.Year c.l.Coarse_rev##c.l.EPL_p l.cce l.ln_pop l.ln_gdp_pc l.IMF_fiscal l.kaopen l.GDPgr l.Fuel l.Age l.IIP_gdp if l.EPL_p!=. || CountryID: l.Coarse_rev 

eststo model2

mixed trade i.Year c.l.Coarse_rev##c.l.EPL_p l.rqe l.ln_pop l.ln_gdp_pc l.IMF_fiscal l.kaopen l.GDPgr l.Fuel l.Age l.IIP_gdp if l.EPL_p!=. || CountryID: l.Coarse_rev 

eststo model3

mixed CAB i.Year c.l.Coarse_rev##c.l.EPL_p l.rqe l.ln_pop l.ln_gdp_pc l.IMF_fiscal l.kaopen l.GDPgr l.Fuel l.Age l.IIP_gdp if l.EPL_p!=. || CountryID: l.Coarse_rev 

eststo model4

esttab model1 model2 model3 model4 using "TableA5.doc", drop(*.Year lns1_1_1:_cons lns1_1_2:_cons lnsig_e:_cons) replace se rtf varlabels(L.Coarse_rev "ERR_{t-1}" L.EPL_p "EPL_{t-1}" cL.Coarse_rev#cL.EPL_p "ERR_{t-1}#EPL_{t-1}" L.cce "Corruption_{t-1}" L.rqe "Regulation_{t-1}" L.ln_pop "LogPopulation_{t-1}" L.ln_gdp_pc "LogGDPpc_{t-1}" L.IMF_fiscal_balance "FiscalBalance_{t-1}" L.kaopen "Openness_{t-1}" L.GDPgrowthannual "GDPgrowth_{t-1}" L.Fuelexports "FuelExports_{t-1}" L.Agedependencyratioold "AgeDependencyRatio_{t-1}" L.IIP_gdp "IIPtoGDP_{t-1}") stats(p N, fmt(%9.3f %9.0f) labels("P" "N")) mtitles ("Model 1 (trade)" "Model 2 (CAB)" "Model 3 (trade)" "Model 4 (CAB)") nonumbers nodepvars star(* 0.1 ** 0.05 *** 0.01)





*** Excluding Eurozone members (Figures 5 and 6)

mixed trade i.Year l.ln_pop l.ln_gdp_pc l.IMF_fiscal l.kaopen l.GDPgr l.Fuel l.Age l.IIP_gdp c.l.Coarse_rev##c.l.EPL_p if l.EPL_p!=. & l.euro==0 || CountryID: l.Coarse_rev
margins, dydx(l.Coarse_rev) at(l.EPL_p = (0.1 (0.1) 5))
marginsplot, yline(0) xtitle("EPL (Lagged)") title("")
graph export "Figure5.png", replace


mixed CAB i.Year l.ln_pop l.ln_gdp_pc l.IMF_fiscal l.kaopen l.GDPgr l.Fuel l.Age l.IIP_gdp c.l.Coarse_rev##c.l.EPL_p if l.EPL_p!=. & l.euro==0 || CountryID: l.Coarse_rev
margins, dydx(l.Coarse_rev) at(l.EPL_p = (0.1 (0.1) 5))
marginsplot, yline(0) xtitle("EPL (Lagged)") title("")
graph export "Figure6.png", replace



*** LP-DiD models



*** First, let us look at treatment status

*** Figure A1
panelview trade Fixed_hard EPL_p developed if EPL_p!=. & EPL_p < 2.9 & developed==1, i(CountryID) t(Year) type(treat) bytiming title("Treatment Status") ytitle("")

graph export "FigureA1.png", as(png) replace


*** Figure A2
panelview trade Fixed_hard EPL_p developed if EPL_p!=. & EPL_p > 2.9 & developed==1, i(CountryID) t(Year) type(treat) bytiming title("Treatment Status") ytitle("")

graph export "FigureA2.png", as(png) replace

*** Figure 7

lpdid trade if EPL_p!=. &  EPL_p <  2.9 & developed==1, time(Year) unit(CountryID) treat(Fixed_hard) pre(5) post(10) cluster(Country) nonabs(4) nocomp
graph save "Figure7-1.gph", replace

lpdid trade if EPL_p!=. &  EPL_p >  2.9 & developed==1, time(Year) unit(CountryID) treat(Fixed_hard) pre(5) post(10) cluster(Country) nonabs(4) nocomp
graph save "Figure7-2.gph", replace

lpdid CAB if EPL_p!=. &  EPL_p <  2.9 & developed==1, time(Year) unit(CountryID) treat(Fixed_hard) pre(5) post(10) cluster(Country) nonabs(4) nocomp
graph save "Figure7-3.gph", replace

lpdid CAB if EPL_p!=. &  EPL_p >  2.9 & developed==1, time(Year) unit(CountryID) treat(Fixed_hard) pre(5) post(10) cluster(Country) nonabs(4) nocomp
graph save "Figure7-4.gph", replace

graph combine "Figure7-1.gph" "Figure7-2.gph" "Figure7-3.gph" "Figure7-4.gph", col(2) imargin(0.05 1.5 0.05 0.05) xsize(7) ysize(7)
graph export "Figure7.png", as(png) replace


*** Figure A3

lpdid trade if EPL_p!=. &  EPL_p <  2.9 & developed==1, time(Year) unit(CountryID) treat(Fixed_hard) pre(5) post(10) cluster(Country) nonabs(4) nocomp ylags(1)

graph save "FigureA3-1.gph", replace

lpdid trade if EPL_p!=. &  EPL_p >  2.9 & developed==1, time(Year) unit(CountryID) treat(Fixed_hard) pre(5) post(10) cluster(Country) nonabs(4) nocomp  ylags(1)

graph save "FigureA3-2.gph", replace

lpdid CAB if EPL_p!=. &  EPL_p <  2.9 & developed==1, time(Year) unit(CountryID) treat(Fixed_hard) pre(5) post(10) cluster(Country) nonabs(4) nocomp ylags(1)

graph save "FigureA3-3.gph", replace

lpdid CAB if EPL_p!=. &  EPL_p >  2.9 & developed==1, time(Year) unit(CountryID) treat(Fixed_hard) pre(5) post(10) cluster(Country) nonabs(4) nocomp ylags(1)

graph save "FigureA3-4.gph", replace

graph combine "FigureA3-1.gph" "FigureA3-2.gph" "FigureA3-3.gph" "FigureA3-4.gph", col(2) imargin(0.05 1.5 0.05 0.05) xsize(7) ysize(7)
graph export "FigureA3.png", as(png) replace



*** Using first difference of the DV - no Figure in the text
lpdid trade if EPL_p!=. &  EPL_p <  2.9 & developed==1, time(Year) unit(CountryID) treat(Fixed_hard) pre(5) post(10) cluster(Country) nonabs(4) nocomp dylags(1)

lpdid trade if EPL_p!=. &  EPL_p >  2.9 & developed==1, time(Year) unit(CountryID) treat(Fixed_hard) pre(5) post(10) cluster(Country) nonabs(4) nocomp dylags(1)

lpdid CAB if EPL_p!=. &  EPL_p <  2.9 & developed==1, time(Year) unit(CountryID) treat(Fixed_hard) pre(5) post(10) cluster(Country) nonabs(4) nocomp dylags(1)

lpdid CAB if EPL_p!=. &  EPL_p >  2.9 & developed==1, time(Year) unit(CountryID) treat(Fixed_hard) pre(5) post(10) cluster(Country) nonabs(4) nocomp dylags(1)



*** for CAB under flexible, no significant trends only under the following specifications:

** Figure A4

lpdid CAB if EPL_p!=. &  EPL_p >  2.9 & developed==1, time(Year) unit(CountryID) treat(Fixed_hard) pre(5) post(10) cluster(Country) nonabs(4, notyet) nocomp controls (ln_pop ln_gdp_pc IMF_fiscal kaopen GDPgr Fuel Age IIP_gdp)

graph save "FigureA4-1.gph", replace

lpdid CAB if EPL_p!=. &  EPL_p >  2.9 & developed==1, time(Year) unit(CountryID) treat(Fixed_hard) pre(5) post(10) cluster(Country) nonabs(4, notyet) nocomp controls (ln_pop ln_gdp_pc IMF_fiscal kaopen GDPgr Fuel Age IIP_gdp) dylags(1)

graph save "FigureA4-2.gph", replace

graph combine "FigureA4-1.gph" "FigureA4-2.gph", col(1) imargin(0.05 1.5 0.05 0.05) xsize(7) ysize(10)
graph export "FigureA4.png", as(png) replace



*** alternatively, we can lower the threshold for definition of flexible LMI (results are not reported in the text)

lpdid CAB if EPL_p!=. &  EPL_p >  2.4 & developed==1, time(Year) unit(CountryID) treat(Fixed_hard) pre(5) post(10) cluster(Country) nonabs(4) nocomp

lpdid CAB if EPL_p!=. &  EPL_p >  2.4 & developed==1, time(Year) unit(CountryID) treat(Fixed_hard) pre(5) post(10) cluster(Country) nonabs(4) nocomp  ylags(1)

lpdid CAB if EPL_p!=. &  EPL_p >  2.4 & developed==1, time(Year) unit(CountryID) treat(Fixed_hard) pre(5) post(10) cluster(Country) nonabs(4) nocomp dylags(1)



*** let us lower the threshold for rigid LMI:

*** Figure A5
panelview trade Fixed_hard EPL_p developed if EPL_p!=. & EPL_p < 2.4 & developed==1, i(CountryID) t(Year) type(treat) bytiming title("Treatment Status") ytitle("")

graph export "FigureA5.png", as(png) replace

*** Figure 8

lpdid trade if EPL_p!=. &  EPL_p <  2.4 & developed==1, time(Year) unit(CountryID) treat(Fixed_hard) pre(5) post(10) cluster(Country) nonabs(4) nocomp

graph save "Figure8-1.gph", replace

lpdid CAB if EPL_p!=. &  EPL_p <  2.4 & developed==1, time(Year) unit(CountryID) treat(Fixed_hard) pre(5) post(10) cluster(Country) nonabs(4) nocomp

graph save "Figure8-2.gph", replace

graph combine "Figure8-1.gph" "Figure8-2.gph", col(1) imargin(0.05 1.5 0.05 0.05) xsize(7) ysize(10)
graph export "Figure8.png", as(png) replace

*** specifications with lags (not reported in the text)

lpdid trade if EPL_p!=. &  EPL_p <  2.4 & developed==1, time(Year) unit(CountryID) treat(Fixed_hard) pre(5) post(10) cluster(Country) nonabs(4) nocomp ylags(1)

lpdid CAB if EPL_p!=. &  EPL_p <  2.4 & developed==1, time(Year) unit(CountryID) treat(Fixed_hard) pre(5) post(10) cluster(Country) nonabs(4) nocomp ylags(1)

lpdid trade if EPL_p!=. &  EPL_p <  2.4 & developed==1, time(Year) unit(CountryID) treat(Fixed_hard) pre(5) post(10) cluster(Country) nonabs(4) nocomp dylags(1)

lpdid CAB if EPL_p!=. &  EPL_p <  2.4 & developed==1, time(Year) unit(CountryID) treat(Fixed_hard) pre(5) post(10) cluster(Country) nonabs(4) nocomp dylags(1)





*** Generalization with Fraser's index (Table 5)

mixed trade i.Year c.l.Coarse_rev##c.l.labor if l.labor!=. || CountryID: l.Coarse_rev
eststo model1

mixed trade i.Year l.ln_pop l.ln_gdp_pc l.IMF_fiscal l.kaopen l.GDPgr l.Fuel l.Age l.IIP_gdp c.l.Coarse_rev##c.l.labor if l.labor!=. || CountryID: l.Coarse_rev
eststo model2

mixed CAB i.Year c.l.Coarse_rev##c.l.labor if l.labor!=. || CountryID: l.Coarse_rev
eststo model3

mixed CAB i.Year l.ln_pop l.ln_gdp_pc l.IMF_fiscal l.kaopen l.GDPgr l.Fuel l.Age l.IIP_gdp c.l.Coarse_rev##c.l.labor if l.labor!=. || CountryID: l.Coarse_rev
eststo model4


esttab model1 model2 model3 model4 using "Table5.doc", drop(*.Year lns1_1_1:_cons lns1_1_2:_cons lnsig_e:_cons) replace se rtf varlabels(L.Coarse_rev "ERR_{t-1}" L.labor "FraserLabor_{t-1}" cL.Coarse_rev#cL.labor "ERR_{t-1}#FraserLabor_{t-1}" L.ln_pop "LogPopulation_{t-1}" L.ln_gdp_pc "LogGDPpc_{t-1}" L.IMF_fiscal_balance "FiscalBalance_{t-1}" L.kaopen "Openness_{t-1}" L.GDPgrowthannual "GDPgrowth_{t-1}" L.Fuelexports "FuelExports_{t-1}" L.Agedependencyratioold "AgeDependencyRatio_{t-1}" L.IIP_gdp "IIPtoGDP_{t-1}") stats(p N, fmt(%9.3f %9.0f) labels("p" "N")) mtitles ("Model 1 (trade)" "Model 2 (trade)" "Model 3 (CAB)" "Model 4 (CAB)") nonumbers nodepvars star(* 0.1 ** 0.05 *** 0.01)


*** Marginal effects plots, Figures 9 and 10

mixed trade i.Year l.ln_pop l.ln_gdp_pc l.IMF_fiscal l.kaopen l.GDPgr l.Fuel l.Age l.IIP_gdp c.l.Coarse_rev##c.l.labor if l.labor!=. || CountryID: l.Coarse_rev
margins, dydx(l.Coarse_rev) at(l.labor = (1.5 (0.5) 9.5))
marginsplot, yline(0) xtitle("Fraser LM flexibility (Lagged)") title("")
graph export "Figure13.png", replace

mixed CAB i.Year l.ln_pop l.ln_gdp_pc l.IMF_fiscal l.kaopen l.GDPgr l.Fuel l.Age l.IIP_gdp c.l.Coarse_rev##c.l.labor if l.labor!=. || CountryID: l.Coarse_rev
margins, dydx(l.Coarse_rev) at(l.labor = (1.5 (0.5) 9.5))
marginsplot, yline(0) xtitle("Fraser LM flexibility (Lagged)") title("")
graph export "Figure14.png", replace



***  Excluding Eurozone members

mixed trade i.Year l.ln_pop l.ln_gdp_pc l.IMF_fiscal l.kaopen l.GDPgr l.Fuel l.Age l.IIP_gdp c.l.Coarse_rev##c.l.labor if l.labor!=. & l.euro==0 || CountryID: l.Coarse_rev
margins, dydx(l.Coarse_rev) at(l.labor = (1.5 (1) 9.5))
marginsplot, yline(0)

mixed CAB i.Year l.ln_pop l.ln_gdp_pc l.IMF_fiscal l.kaopen l.GDPgr l.Fuel l.Age l.IIP_gdp c.l.Coarse_rev##c.l.labor if l.labor!=. & l.euro==0 || CountryID: l.Coarse_rev
margins, dydx(l.Coarse_rev) at(l.labor = (1.5 (1) 9.5))
marginsplot, yline(0)


*** Dynamic models

reg trade ltrade i.Year l.ln_pop l.ln_gdp_pc l.IMF_fiscal l.kaopen l.GDPgr l.Fuel l.Age l.IIP_gdp c.l.Coarse_rev##c.l.labor if l.labor!=., cluster(CountryID)

reg CAB lCAB i.Year l.ln_pop l.ln_gdp_pc l.IMF_fiscal l.kaopen l.GDPgr l.Fuel l.Age l.IIP_gdp c.l.Coarse_rev##c.l.labor if l.labor!=., cluster(CountryID)


*** Panel DiD


*** first, generate Labor to replace missing values prior to 2000:
gen Labor = labor

bysort CountryID (Year): replace Labor = Labor[_n-1] if missing(Labor)

*** Figure A6

lpdid trade if Labor!=. &  Labor <  6.11, time(Year) unit(CountryID) treat(Fixed_hard) pre(5) post(10) cluster(Country) nonabs(4) nocomp
graph save "FigureA6-1.gph", replace

lpdid trade if Labor!=. &  Labor >  6.11, time(Year) unit(CountryID) treat(Fixed_hard) pre(5) post(10) cluster(Country) nonabs(4) nocomp
graph save "FigureA6-2.gph", replace

lpdid CAB if Labor!=. & Labor < 6.11, time(Year) unit(CountryID) treat(Fixed_hard) pre(5) post(10) cluster(Country) nonabs(4) nocomp
graph save "FigureA6-3.gph", replace

lpdid CAB if Labor!=. & Labor > 6.11, time(Year) unit(CountryID) treat(Fixed_hard) pre(5) post(10) cluster(Country) nonabs(4) nocomp
graph save "FigureA6-4.gph", replace

graph combine "FigureA6-1.gph" "FigureA6-2.gph" "FigureA6-3.gph" "FigureA6-4.gph", col(2) imargin(0.05 1.5 0.05 0.05) xsize(7) ysize(7)
graph export "FigureA6.png", as(png) replace


*** Figure A7 - lagged value of the first difference of the dependent variable

lpdid trade if Labor!=. &  Labor <  6.11, time(Year) unit(CountryID) treat(Fixed_hard) pre(5) post(10) cluster(Country) nonabs(4) nocomp dylags(1)
graph save "FigureA7-1.gph", replace

lpdid trade if Labor!=. &  Labor >  6.11, time(Year) unit(CountryID) treat(Fixed_hard) pre(5) post(10) cluster(Country) nonabs(4) nocomp dylags(1)
graph save "FigureA7-2.gph", replace

lpdid CAB if Labor!=. & Labor < 6.11, time(Year) unit(CountryID) treat(Fixed_hard) pre(5) post(10) cluster(Country) nonabs(4) nocomp dylags(1)
graph save "FigureA7-3.gph", replace

lpdid CAB if Labor!=. & Labor > 6.11, time(Year) unit(CountryID) treat(Fixed_hard) pre(5) post(10) cluster(Country) nonabs(4) nocomp dylags(1)
graph save "FigureA7-4.gph", replace

graph combine "FigureA7-1.gph" "FigureA7-2.gph" "FigureA7-3.gph" "FigureA7-4.gph", col(2) imargin(0.05 1.5 0.05 0.05) xsize(7) ysize(7)
graph export "FigureA7.png", as(png) replace


*** Lagged values (no graph) 


lpdid trade if Labor!=. &  Labor <  6.11, time(Year) unit(CountryID) treat(Fixed_hard) pre(5) post(10) cluster(Country) nonabs(4) nocomp ylags(1)

lpdid trade if Labor!=. &  Labor >  6.11, time(Year) unit(CountryID) treat(Fixed_hard) pre(5) post(10) cluster(Country) nonabs(4) nocomp  ylags(1)

lpdid CAB if Labor!=. & Labor < 6.11, time(Year) unit(CountryID) treat(Fixed_hard) pre(5) post(10) cluster(Country) nonabs(4) nocomp ylags(1)

lpdid CAB if Labor!=. & Labor > 6.11, time(Year) unit(CountryID) treat(Fixed_hard) pre(5) post(10) cluster(Country) nonabs(4) nocomp ylags(1)

